package cn.sf.sufingvideoprovider.serviceImpl;

import cn.sf.pojo.User;
import cn.sf.pojo.Video;
import cn.sf.pojo.VideoClassify;
import cn.sf.service.IndexService;
import cn.sf.sufingvideoprovider.dao.IndexMapper;
import cn.sf.util.RedisUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author sric
 */
@RestController
public class IndexServiceImpl implements IndexService {

    @Resource
    private RedisUtil redisUtil;

    @Resource
    private IndexMapper indexMapper;

    @Override
    @RequestMapping("/queryRandom")
    public String queryRandom() {
        List<Video> videos = indexMapper.queryRandom();
        String stringVideo = JSON.toJSONString(videos);
        boolean set = redisUtil.set("Video:queryRandom", stringVideo);
        if (set) {
            return "true";
        } else {
            return "false";
        }
    }

    @Override
    @RequestMapping("/getRedisQueryRandom")
    public String getRedisQueryRandom() {
        String getQueryRandom = redisUtil.get("Video:queryRandom");
        if (getQueryRandom != null) {
            return getQueryRandom;
        } else {
            return "false";
        }
    }

    @Override
    @RequestMapping("/queryVideoClassify")
    public List<VideoClassify> queryVideoClassify() {
        List<VideoClassify> videoClassifies = indexMapper.queryVideoClassify();
        return videoClassifies;
    }

    @Override
    @RequestMapping("/classificationQueryVideo")
    public List<Video> classificationQueryVideo(Long primary,Long classification, Integer sort) {
        List<Video> videos = indexMapper.classificationQueryVideo(primary,classification, sort);
        return videos;
    }

}
